﻿using Ozone.DAL;
using Ozone.Help;
using Ozone.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ozone.BLL
{
    public class Sys_UserBLL
    {
        private static List<sys_user> _allsys_users;

        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static bool AddUserInfo(sys_user Model)
        {
            bool IsSuccess = false;
            try
            {
                IsSuccess = Sys_UserDAL.AddUserInfo(Model);
            }
            catch (Exception ex)
            {
                LogHelper.Error("添加用户信息异常", ex);
                IsSuccess = false;
            }
            LogHelper.Debug("添加用户信息异常");

            return IsSuccess;
        }

        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public static bool DeleteUserInfo(string ID)
        {
            bool IsSuccess = false;
            try
            {
                SqlSugarScope db = SqlSugarOper.Instance.GetDbClient();
                if (!string.IsNullOrEmpty(ID))
                {
                    IsSuccess = Sys_UserDAL.DeleteUserInfo(ID);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("删除用户信异常", ex);
                IsSuccess = false;
            }
            return IsSuccess;
        }

        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static bool UpdateUserInfo(sys_user model)
        {
            bool IsSuccess = false;
            try
            {
                if (model != null)
                {
                    IsSuccess = Sys_UserDAL.UpdateUserInfo(model);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("修改用户信息异常", ex);
                IsSuccess = false;
            }
            return IsSuccess;
        }

        /// <summary>
        /// 查询用户信息
        /// </summary>
        /// <param name="userID">用户编码</param>
        /// <param name="password">用户密码</param>
        /// <returns></returns>
        public static List<sys_user> GetUserInfoList(string userID, string password)
        {
            try
            {
                _allsys_users = Sys_UserDAL.GetUserInfoList(userID, password);
            }
            catch (Exception ex)
            {
                LogHelper.Error("查询用户信息发生异常", ex);
                _allsys_users = null;
            }
            return _allsys_users;
        }
    }
}